﻿using LINQage;
using System;
using System.Collections.Generic;
using System.Linq;
using Students;

namespace LINQage
{
    //Write a LINQ query that finds the 
    //first name and last name of all 
    //students with age between 18 and 24.

    public class StudentAge : Student
    {
        private int age;

        public StudentAge(string FName, string LName, int age) : base(FName, LName)
        {
            this.Age = age;
        }

        public int Age
        {
            get
            {
                return this.age;
            }
            set
            {
                if (value >= 0 && value <= 120)
                {
                    this.age = value;
                }
                else
                {
                    throw new IndexOutOfRangeException();
                }
            }

        }
        static void Main()
        {
            List<StudentAge> studentList = new List<StudentAge>();
            studentList.Add(new StudentAge("Nikolai", "Aleksiev", 19));
            studentList.Add(new StudentAge("Lacho", "Gerovski", 23));
            studentList.Add(new StudentAge("Iliq", "Stoyanov", 30));



            var queryStudAge =
                from student in studentList
                where student.Age >= 18 && student.Age <= 24
                select student;

            foreach (var stud in queryStudAge)
            {
                Console.WriteLine("{0} {1}", stud.Fname,stud.Lname);
            }
        }
    }
}